home *** CD-ROM | disk | FTP | other *** search
- /*
- * MSGLIST.C - Message header listing
- *
- * Msged/Q message editor for QuickBBS Copyright 1990 by P.J. Muller
- *
- */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
-
- #include "msged.h"
- #include "screen.h"
- #include "qmsgbase.h"
-
- static void update(int n,int y);
- static void showline(int y, BOOLEAN hi);
-
- static char scrwidth[16];
- static BOOLEAN f = TRUE;
- static struct mh {
- MSGHEADER h;
- int n;
- } *headers;
-
- void list()
- {
- int i, y, ch, a;
- char *s;
-
- if (countmsg(CurBoard) < 1) /* area is empty */
- return;
-
- cls();
- sprintf(scrwidth,"%%-%d.%ds",maxx,maxx);
- i = a = curmsg(CurBoard);
- headers = (struct mh *) calloc(maxy+1,sizeof(struct mh));
-
- y = 1;
-
- update(i,y);
-
- ch = 0;
- y = 1;
-
- /* this is still a mess */
-
- while ((ch != ENTER) && (ch != ABORT)) {
- gotoxy(1, y);
- clreol();
- showline(y, TRUE);
-
- switch (ch = getkey()) {
-
- case HELP:
- helplist();
- update(a,1);
- break;
-
- case KAREA :
- case TOGGLE :
- f = !f;
- y = 1;
- update(a,y);
- break;
-
- case PGDN:
- { int last = lastmsg(CurBoard);
- i = maxy-y+1;
- while ((--i > 0) && (a < last))
- a = msgnext(CurBoard,a);
- }
-
- y = 1;
- update(a,y);
- break;
-
- case PGUP:
- { int first = firstmsg(CurBoard);
- i = maxy-1; /* go forward i messages */
-
- while ((i-- > 0) && (a > first))
- a = msgprev(CurBoard, a);
- if (a <= first)
- y = 1;
- }
-
- /* y = 1; */
-
- update(a,1);
- break;
-
- case TOP:
- a = firstmsg(CurBoard);
- y = 1;
- update(a,y);
- break;
-
- case BOTTOM:
- a = lastmsg(CurBoard);
- y = 1;
- update(a,y);
- break;
-
- case UP:
- if (a > firstmsg(CurBoard)) {
- int b = a;
- gotoxy(1, y);
- clreol();
- showline(y, FALSE);
-
- if ((a = msgprev(CurBoard,a)) == 0)
- a = b;
- else
- y--;
-
- if (y < 1) {
- y = 1;
- scrolldown(1, 1, maxx, maxy, 1);
- memmove((headers + 1),headers,(sizeof(struct mh) * maxy));
- if (!readheader(a, &headers[0].h))
- strcpy(headers[0].h.from, "read error");
- s = strchr(headers[0].h.from,'\n');
- if (s != NULL)
- *s = EOS;
- s = strchr(headers[0].h.to,'\n');
- if (s != NULL)
- *s = EOS;
- headers[0].n = a;
- } /* if */
- } /* if */
- break;
-
- case DOWN:
- if (a < lastmsg(CurBoard)) {
- int b = a;
- gotoxy(1, y);
- clreol();
- showline(y, FALSE);
-
- if ((a = msgnext(CurBoard,a)) == 0)
- a = b;
- else
- y++;
-
- if (y > maxy) {
- y = maxy;
- scrollup(1, 1, maxx, maxy, 1);
- memmove(headers,(headers + 1),sizeof(struct mh) * (maxy));
- if (!readheader(a, &headers[maxy-1].h))
- strcpy(headers[maxy-1].h.from,"read error");
- s = strchr(headers[maxy - 1].h.from,'\n');
- if (s != NULL)
- *s = EOS;
- s = strchr(headers[maxy - 1].h.to,'\n');
- if (s != NULL)
- *s = EOS;
- headers[maxy-1].n = a;
- } /* if */
- } /* if */
- break;
-
- case ENTER:
- setcur(CurBoard, a);
- /* readmsg(&message, a); -- done in main */
- ptrfree(headers);
- return;
-
- case ABORT:
- ptrfree(headers);
- return;
-
- case DONE2:
- cleanup();
- break;
-
- } /* switch */
- } /* while */
- } /* list */
-
- /*
- * Update the display from message number 'i' and y coordinate 'y'
- */
-
- static void update(int i,int y)
- {
- int t;
- char *s;
-
- clrwnd(1,y,maxx,maxy);
- do {
- gotoxy(1,y);
- if (!readheader(i, &headers[y-1].h))
- strcpy(headers[y-1].h.from,"read error");
- s = strchr(headers[y - 1].h.from,'\n');
- if (s != NULL)
- *s = EOS;
- s = strchr(headers[y - 1].h.to,'\n');
- if (s != NULL)
- *s = EOS;
- headers[y-1].n = i;
- showline(y++, FALSE);
- i = msgnext(CurBoard,t = i);
- } while ((i != 0) && (i != t) && (y <= maxy));
- } /* update */
-
- static void showline(int y, BOOLEAN hi)
- {
- char line[200];
- char ato[20], afr[20];
-
- sprintf(afr,"%d/%d",headers[y - 1].h.orig_net,headers[y - 1].h.orig);
- sprintf(ato,"%d/%d",headers[y - 1].h.dest_net,headers[y - 1].h.dest);
-
- /* Templates:
- nnnnn: 1234567890123456@123456789 to 1234567890123456@123456789 1234567890123456
- nnnnn: 1234567890123456 to 1234567890123456 123456789012345678901234567890123456
- */
- if (f && arealist[area].netmail)
- sprintf(line,"%5d: %-16.16s@%-9.9s to %-16.16s@%-9.9s %-16.16s", /* 16 */
- headers[y - 1].n,
- headers[y - 1].h.from,
- afr,
- headers[y - 1].h.to,
- ato,
- headers[y - 1].h.subj);
- else
- sprintf(line,"%5d: %-16.16s to %-16.16s %-36.36s", /* 36 */
- headers[y - 1].n,headers[y - 1].h.from,headers[y - 1].h.to,headers[y - 1].h.subj);
-
- if (hi)
- set_color(co_hilite);
- else if (strnicmp(username, headers[y-1].h.to, strlen(username)) == 0)
- set_color(co_quote);
- else set_color(co_normal);
-
- bprintf(scrwidth,line); /* will limit to screen width */
-
- set_color(co_normal);
- } /* showline */